{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "editable": false
   },
   "outputs": [],
   "source": [
    "%grade_logstart 403"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Day 14 Classwork - Problem 4\n",
    "\n",
    "The cell below shows list of earthquake magnitudes. Write a Python program to find and print the number of earthquakes that are above a magnitude that the user specifies. Use a Python *input* operation to prompt the user for the specified magnitude. You can reuse much of the code that you wrote in the answer to Classwork 3.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Initializations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Put here the original state of variables from initializations, inputs, and data from imported functions\n",
    "\n",
    "magnitudes = [1.5, 1.9, 4.3, 2.1, 2.0, 3.6, 0.5, 2.5, 1.9, 4.0, 3.8, 0.7, 2.2, 5.1, 1.6]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Processing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Put here the computation that produces the desired result(s).\n",
    "mag = 0\n",
    "filt = float(input(\"fun:\"))\n",
    "for item in magnitudes:\n",
    "    if item > filt:\n",
    "        mag = mag + 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Put here the code to print or plot the result(s).\n",
    "print(mag)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Feedback"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "\n",
       "// Convert Notebook cells to a string of Python code\n",
       "var makePython = function(cell) {\n",
       "    if (cell.cell_type == \"code\") {\n",
       "        // Code is embedded unchanged, unless it is magic\n",
       "        var source = cell.get_text();\n",
       "        if (source.startsWith('%')) {\n",
       "            // Skip magic\n",
       "            return '';\n",
       "        } else {\n",
       "            return source;\n",
       "        }\n",
       "    } else if (cell.cell_type == \"markdown\" ||\n",
       "               cell.cell_type == \"raw\") {\n",
       "        // Markdown and text is wrapped in a string.\n",
       "        var escaped_text = cell.get_text().replace(/'''/g, \"\\\\'\\\\'\\\\'\");\n",
       "        return \"'''\"+escaped_text+\"'''\";\n",
       "    }\n",
       "}\n",
       "var isUsable = function(cell) {\n",
       "    return cell.cell_type == \"code\" ||\n",
       "           cell.cell_type == \"markdown\" ||\n",
       "           cell.cell_type == \"raw\";\n",
       "}\n",
       "var cells = Jupyter.notebook.get_cells();\n",
       "var source_code = cells.filter(isUsable).map(makePython).join(\"\\n\");\n",
       "source_code = JSON.stringify(source_code);\n",
       "console.log(source_code);\n",
       "// Start constructing the feedback code (which will be Python).\n",
       "var on_run_code = [];\n",
       "on_run_code.push(\"student_code=\"+source_code);\n",
       "\n",
       "// While we are accessing the server, recolor the last cell a little.\n",
       "var last = null;\n",
       "if (cells.length > 0) {\n",
       "    last = cells[cells.length-1];\n",
       "    $(last.element).animate({\"background-color\": \"#E0E6FF\"}, 1000);\n",
       "}\n",
       "\n",
       "on_run_code.push(\"from pedal.plugins.grade_magic import blockpy_grade\");\n",
       "on_run_code.push('import json')\n",
       "on_run_code.push('inputs = json.dumps(\"\")')\n",
       "on_run_code.push(\"print(blockpy_grade(403, student_code, inputs))\");\n",
       "\n",
       "on_run_code = on_run_code.join(\"\\n\");\n",
       "console.log(on_run_code);\n",
       "var kernel = IPython.notebook.kernel;\n",
       "if (kernel !== null) {\n",
       "    var t = kernel.execute(on_run_code, { 'iopub' : {'output' : function(x) {\n",
       "        if (x.msg_type == \"error\") {\n",
       "            // If this was an error, show the traceback properly.\n",
       "            if (last !== null) {\n",
       "                last.output_area.append_error(x.content);\n",
       "                console.error(x);\n",
       "            } else {\n",
       "                console.error(\"Could not append to final cell.\", x);\n",
       "            }\n",
       "        } else if (!x.content.data && x.content.text) {\n",
       "            // If it was valid data, we show it as HTML.\n",
       "            console.log(x);\n",
       "            element.html(x.content.text.replace(/\\n/g, \"<br>\"));\n",
       "        } else {\n",
       "            // I'm not sure what it is - better dump it on the console.\n",
       "            console.log(x);\n",
       "        }\n",
       "        // Decolor the last cell if it was there.\n",
       "        if (last !== null) {\n",
       "            last = cells[cells.length-1];\n",
       "            $(last.element).animate({\"background-color\": \"white\"}, 1000);\n",
       "        }\n",
       "    }}});\n",
       "}"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%grade_blockpy 403,1000\n",
    "# New problem - need new feedback. Can reuse feedback from Problem 3"
   ]
  }
 ],
 "metadata": {
  "comet_tracking": true,
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  },
  "student_mode": false
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
